{{!
  Copyright (c) HashiCorp, Inc.
  SPDX-License-Identifier: BUSL-1.1
~}}

{{#if (has-feature "Namespaces")}}
  <PageHeader as |p|>
    <p.levelLeft>
      <h1 class="title is-3">
        Namespaces
      </h1>
    </p.levelLeft>
  </PageHeader>

  <Toolbar>
    <ToolbarActions>
      <ToolbarLink @route="vault.cluster.access.namespaces.create" @type="add">
        Create namespace
      </ToolbarLink>
    </ToolbarActions>
  </Toolbar>

  <ListView @items={{this.model}} @itemNoun="namespace" @paginationRouteName="vault.cluster.access.namespaces" as |list|>
    {{#if list.empty}}
      <list.empty>
        <LinkTo @route="vault.cluster.access.namespaces.create">
          Create Namespace
        </LinkTo>

        <DocLink @path="/vault/tutorials/enterprise/namespaces">
          Learn more
        </DocLink>
      </list.empty>
    {{else}}
      <ListItem as |Item|>
        <Item.content>
          {{list.item.id}}
        </Item.content>
        <Item.menu>
          {{#let (concat this.currentNamespace (if this.currentNamespace "/") list.item.id) as |targetNamespace|}}
            {{#if (includes targetNamespace this.accessibleNamespaces)}}
              <li class="action">
                <NamespaceLink @targetNamespace={{targetNamespace}} @unparsed={{true}} @class="is-block">
                  Switch to Namespace
                </NamespaceLink>
              </li>
            {{/if}}
          {{/let}}
          <ConfirmAction
            @isInDropdown={{true}}
            @buttonText="Delete"
            @confirmTitle="Delete this namespace?"
            @confirmMessage="Any engines or mounts in this namespace will also be removed."
            @onConfirmAction={{action
              (perform
                Item.callMethod
                "destroyRecord"
                list.item
                (concat "Successfully deleted namespace: " list.item.id)
                "There was an error deleting this namespace: "
                (action "refreshNamespaceList")
              )
            }}
          />
        </Item.menu>
      </ListItem>
    {{/if}}
  </ListView>
{{else}}
  <UpgradePage @title="Namespaces" @minimumEdition="Vault Enterprise Pro" />
{{/if}}